home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / raid / devRaidMap.c < prev    next >
C/C++ Source or Header  |  1990-10-12  |  6KB  |  215 lines

  1. /* 
  2.  * devRaidUtil.c --
  3.  *
  4.  *    Routines for allocating, initializing and deallocating various
  5.  *    RAID data structures.
  6.  *    Routines for mapping logical RAID sectors to physical devices.
  7.  *
  8.  * Copyright 1989 Regents of the University of California
  9.  * All rights reserved.
  10.  * Permission to use, copy, modify, and distribute this
  11.  * software and its documentation for any purpose and without
  12.  * fee is hereby granted, provided that the above copyright
  13.  * notice appear in all copies.  The University of California
  14.  * makes no representations about the suitability of this
  15.  * software for any purpose.  It is provided "as is" without
  16.  * express or implied warranty.
  17.  */
  18.  
  19. #ifndef lint
  20. static char rcsid[] = "$Header: /sprite/src/kernel/raid/RCS/devRaidMap.c,v 1.3 90/10/12 14:01:09 eklee Exp $ SPRITE (Berkeley)";
  21. #endif /* not lint */
  22.  
  23. #include "sync.h"
  24. #include <stdio.h>
  25. #include "sprite.h"
  26. #include "fs.h"
  27. #include "dev.h"
  28. #include "devBlockDevice.h"
  29. #include "devRaid.h"
  30. #include "stdlib.h"
  31. #include "devRaidUtil.h"
  32. #include "machparam.h"
  33.  
  34.  
  35. /*
  36.  *----------------------------------------------------------------------
  37.  *
  38.  * Raid_MapPhysicalToStripeID --
  39.  *
  40.  *    Maps physical address (raid, col, row, sector) to stripeID.
  41.  *
  42.  * Results:
  43.  *    stripeID
  44.  *
  45.  * Side effects:
  46.  *    None.
  47.  *
  48.  *----------------------------------------------------------------------
  49.  */
  50.  
  51. void
  52. Raid_MapPhysicalToStripeID(raidPtr, col, row, sector, outStripeIDPtr)
  53.     Raid    *raidPtr;
  54.     int         col;
  55.     int         row;
  56.     unsigned     sector;
  57.     int        *outStripeIDPtr;
  58. {
  59.     int group, groupRow, stripeUnit;
  60.     int stripeID;
  61.  
  62.     group    = row / raidPtr->rowsPerGroup;
  63.     groupRow = row % raidPtr->rowsPerGroup;
  64.     stripeUnit = sector / raidPtr->sectorsPerStripeUnit;
  65.  
  66.     stripeID = group * raidPtr->stripeUnitsPerDisk + stripeUnit;
  67.     stripeID = stripeID * raidPtr->rowsPerGroup + groupRow;
  68.     *outStripeIDPtr = stripeID;
  69. }
  70.  
  71.  
  72. /*
  73.  *----------------------------------------------------------------------
  74.  *
  75.  * Raid_MapParity --
  76.  *
  77.  *    Maps logical sector address to (col, row, sector) of corresponding
  78.  *    parity sector.
  79.  *
  80.  * Results:
  81.  *      (col, row, sector).
  82.  *
  83.  * Side effects:
  84.  *    None.
  85.  *
  86.  *----------------------------------------------------------------------
  87.  */
  88.  
  89. void
  90. Raid_MapParity(raidPtr, sectorNum, outColPtr, outRowPtr, sectorNumPtr)
  91.     Raid    *raidPtr;
  92.     unsigned     sectorNum;
  93.     int        *outColPtr, *outRowPtr;
  94.     unsigned    *sectorNumPtr;
  95. {
  96.     int sector, col, groupRow, stripeUnit, group;
  97.     int row, stripeID;
  98.  
  99.     sector     = sectorNum%raidPtr->sectorsPerStripeUnit;
  100.     sectorNum /= raidPtr->sectorsPerStripeUnit;
  101.     col        = sectorNum%raidPtr->numDataCol;
  102.     sectorNum /= raidPtr->numDataCol;
  103.     groupRow   = sectorNum%raidPtr->rowsPerGroup;
  104.     sectorNum /= raidPtr->rowsPerGroup;
  105.     stripeUnit = sectorNum%raidPtr->stripeUnitsPerDisk;
  106.     sectorNum /= raidPtr->stripeUnitsPerDisk;
  107.     group      = sectorNum%raidPtr->groupsPerArray;
  108.     sectorNum /= raidPtr->groupsPerArray;
  109.  
  110.     if (sectorNum != 0) {
  111.     (void)printf("Error: Raid_MapSector: sectorNum=%d\n", (int) sectorNum);
  112.     }
  113.  
  114.     row = group * raidPtr->rowsPerGroup + groupRow;
  115.     stripeID = group * raidPtr->stripeUnitsPerDisk + stripeUnit;
  116.     stripeID = stripeID * raidPtr->rowsPerGroup + groupRow;
  117.  
  118.     /*
  119.      * Rotate sectors/parity.
  120.      */
  121.     switch (raidPtr->parityConfig) {
  122.     case 'R': /* Right Symetric */
  123.     col = (raidPtr->numCol-1 + stripeID) % raidPtr->numCol;
  124.     break;
  125.     case 'L': /* Left Symetric */
  126.     col = (raidPtr->numCol-1 - stripeID) % raidPtr->numCol;
  127.     if (col < 0) {
  128.         col += raidPtr->numCol;
  129.     }
  130.     break;
  131.     default:  /* No Rotation */
  132.     col = raidPtr->numCol-1;
  133.     break;
  134.     }
  135.  
  136.     /*
  137.      * Return values.
  138.      */
  139.     *outColPtr = col;
  140.     *outRowPtr = row;
  141.     *sectorNumPtr = stripeUnit*raidPtr->sectorsPerStripeUnit + sector;
  142.     return;
  143. }
  144.  
  145.  
  146. /*
  147.  *----------------------------------------------------------------------
  148.  *
  149.  * Raid_MapSector --
  150.  *
  151.  *    Maps logical sector address to (col, row, sector).
  152.  *
  153.  * Results:
  154.  *      (col, row, sector).
  155.  *
  156.  * Side effects:
  157.  *    None.
  158.  *
  159.  *----------------------------------------------------------------------
  160.  */
  161.  
  162. void
  163. Raid_MapSector(raidPtr, sectorNum, outColPtr, outRowPtr, sectorNumPtr)
  164.     Raid    *raidPtr;
  165.     unsigned     sectorNum;
  166.     int        *outColPtr, *outRowPtr;
  167.     unsigned    *sectorNumPtr;
  168. {
  169.     int sector, col, groupRow, stripeUnit, group;
  170.     int row, stripeID;
  171.  
  172.     sector     = sectorNum%raidPtr->sectorsPerStripeUnit;
  173.     sectorNum /= raidPtr->sectorsPerStripeUnit;
  174.     col        = sectorNum%raidPtr->numDataCol;
  175.     sectorNum /= raidPtr->numDataCol;
  176.     groupRow   = sectorNum%raidPtr->rowsPerGroup;
  177.     sectorNum /= raidPtr->rowsPerGroup;
  178.     stripeUnit = sectorNum%raidPtr->stripeUnitsPerDisk;
  179.     sectorNum /= raidPtr->stripeUnitsPerDisk;
  180.     group      = sectorNum%raidPtr->groupsPerArray;
  181.     sectorNum /= raidPtr->groupsPerArray;
  182.  
  183.     if (sectorNum != 0) {
  184.     (void)printf("Error: Raid_MapSector: sectorNum=%d\n", (int) sectorNum);
  185.     }
  186.  
  187.     row = group * raidPtr->rowsPerGroup + groupRow;
  188.     stripeID = group * raidPtr->stripeUnitsPerDisk + stripeUnit;
  189.     stripeID = stripeID * raidPtr->rowsPerGroup + groupRow;
  190.  
  191.     /*
  192.      * Rotate sectors/parity.
  193.      */
  194.     switch (raidPtr->parityConfig) {
  195.     case 'R': /* Right Symetric */
  196.     col = (col + stripeID) % raidPtr->numCol;
  197.     break;
  198.     case 'L': /* Left Symetric */
  199.     col = (col - stripeID) % raidPtr->numCol;
  200.     if (col < 0) {
  201.         col += raidPtr->numCol;
  202.     }
  203.     break;
  204.     default:  /* No Rotation */
  205.     break;
  206.     }
  207.  
  208.     /*
  209.      * Return values.
  210.      */
  211.     *outColPtr = col;
  212.     *outRowPtr = row;
  213.     *sectorNumPtr = stripeUnit*raidPtr->sectorsPerStripeUnit + sector;
  214. }
  215.